﻿using System.Collections;
using System.Collections.Generic;
using Uniblocks;
using UnityEngine;
using TinyTeam.UI;


public class GameManager : MonoBehaviour
{
    public Camera mainCamera;
    public GameObject PlayerPref;
    public Transform playerTrans;
    public static GameManager instance;
    private void Awake()
    {
        instance = this;
    }
    // Use this for initialization
    void Start()
    {
        Utl.instance.WaitForFrame(4, () =>
        {
            Vector3 pos;
            Utl.instance.WaitForTrue(CheckCanInsPlayer, () =>
            {
                //关闭加载界面
                TTUIPage.ClosePage<LoadUI>();
                //玩家生成
                playerTrans = Instantiate(PlayerPref).transform;
                mainCamera = playerTrans.GetComponentInChildren<Camera>();
                RaycastHit hit;
                Physics.Raycast(Vector3.up * 100, Vector3.down, out hit, 100);
                playerTrans.position = hit.point;
            });
        });
    }

    bool CheckCanInsPlayer()
    {
        RaycastHit hit;
        Physics.Raycast(Vector3.up * 100, Vector3.down, out hit, 100);
        if (hit.point == Vector3.zero)
            return false;
        else
        return true;
    }

    // Update is called once per frame
    void Update()
    {

    }
}
